package com.weacar.utils;

import android.app.Activity;

import android.util.DisplayMetrics;


/**
 * 获取屏幕宽高参数，用于适配Android全机型屏幕适配
 * <meta-data
 * android:name="design_width_in_dp"
 * android:value="screenWidth" />
 * <meta-data
 * android:name="design_height_in_dp"
 * android:value="screenHeight" />
 */
public class ScreenUtil {

    public static String getScreenInfo(Activity activity) {

        DisplayMetrics metric = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metric);

        int width = metric.widthPixels; // 宽度（PX）
        int height = metric.heightPixels; // 高度（PX）

        float density = metric.density; // 密度（0.75 / 1.0 / 1.5）
        int densityDpi = metric.densityDpi; // 密度DPI（120 / 160 / 240）
        //屏幕宽度算法:屏幕宽度（像素）/屏幕密度
        int screenWidth = (int) (width / density);//屏幕宽度(dp)
        int screenHeight = (int) (height / density);//屏幕高度(dp)
        return "screenWidth = " + screenWidth + "screenHeight = " + screenHeight + "dpi = " + densityDpi;
    }
}
